package operation;
import book.List.book ;
import book.List.bookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:岁亮亮
 * Date:2024-01-08
 * TIME:19:24
 */
public class deloperation implements IOoperation {

    @Override
    public void work(bookList bookList) {
        System.out.println("删除图书");
        System.out.println("请输出你要删除的图书");
        Scanner scanner=new Scanner(System.in);
        String str=scanner.nextLine();
        int pos=-1;
        for (int i = 0; i < bookList.getUsesize(); i++) {
            book book=bookList .getBook(i);
            if(book.getName() .equals(str)){
                 pos=i;
                break;

            }
        }
        if(pos==-1){
            System.out.println("没有找到要删除的图书");
        }
        else{
            for (int j = pos; j <bookList.getUsesize() -1; j++) {
                //bookList .getBooks() [j]=bookList .getBooks() [j+1];
                book book1=bookList.getBook(j+1);
                bookList.setBooks(j,book1);

            }
            int endnumber=bookList .getUsesize();
            bookList .setBooks(endnumber,null);
            bookList .setUsesize(endnumber-1);
            System.out.println("删除成功");
        }




    }
}
